package com.logos.tool;

import android.os.CountDownTimer;

/**
 * @author yh
 * @discrebe//
 * @email 153108317@qq.com
 * @date 2018/1/17 0017
 */

public class TimerUtil extends CountDownTimer {

    public static long remainTime = 60 * 1000;
    public static long countDownInterval = 1000;
    private IsendProgress isendProgress;

    /**
     * @param millisInFuture    The number of millis in the future from the call
     *                          to {@link #start()} until the countdown is done and {@link #onFinish()}
     *                          is called.
     * @param countDownInterval The interval along the way to receive
     *                          {@link #onTick(long)} callbacks.
     */
    public TimerUtil(long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);
    }

    public TimerUtil(IsendProgress isendProgress) {
        super(remainTime, countDownInterval);
        this.isendProgress = isendProgress;
    }

    @Override
    public void onTick(long millisUntilFinished) {
        if (isendProgress != null) {
            isendProgress.sentProgress("" + millisUntilFinished / 1000);
        }
    }

    @Override
    public void onFinish() {
        if (isendProgress != null) {
            isendProgress.onFinish();
        }
    }

    public interface IsendProgress {

        void sentProgress(String progress);

        void onFinish();
    }
}
